package com.fengpb.friday.conductor.dao.mapper;

import com.fengpb.friday.conductor.common.metadata.task.TaskDef;
import com.fengpb.friday.conductor.common.metadata.workflow.WorkflowDef;
import com.fengpb.friday.conductor.dao.mapper.provider.MetadataMapperProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MetadataMapper {

    @Select("select json_data from meta_workflow_def")
    List<WorkflowDef> getAllWorkflowDef();

    @Select("select json_data from meta_workflow_def where name = #{name} and version = #{version}")
    WorkflowDef getWorkflowDef(@Param("name") String name, @Param("version") int version);

    @Insert("insert into meta_workflow_def (name, version, latest_version, json_data) values " +
            "(#{def.name}, #{def.version}, #{latest_version}, #{json_data})")
    Integer registerWorkflowDef(WorkflowDef def, int latest_version, String json_data);

    Integer registerTaskDef(TaskDef def);

    @Update("update meta_workflow_def set json_data = #{json_data}, modified_on = now() where name = #{def.name} and version = #{def.version}")
    Integer updateWorkflowDef(WorkflowDef def, int latest_version, String json_data);

    Integer updateTaskDef(TaskDef def);
}
